package edu.jd.block_chain.security.home;

import edu.jd.block_chain.common.CommonService;
import edu.jd.block_chain.common.CurrentUser;
import edu.jd.block_chain.common.Result;
import edu.jd.block_chain.common.TokenUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @descriptions: 此类用于当前用户信息
 * @data: 2021/11/23 21:34
 */
@RestController
@RequestMapping("/security/home")
public class HomeAPI {

    @Resource
    private CommonService commonService;
//    @Resource
//    private HomeService homeService;

    @GetMapping("/currentUser")
    public Result currentUser(@RequestHeader("Token") String token) {
        CurrentUser currentUser = TokenUtils.getUserInfo(token, commonService);

        return Result.success(currentUser);
    }

    @DeleteMapping("/exit")
    public Result exit(@RequestHeader("Token") String token) {
        //在服务端清除缓存的token
        TokenUtils.removeToken(token);
        return Result.success();
    }
}
